function paging (option){

    this.params = {
        index:1,
        page:5,
        maxPage:0,
        url:'#',
        urlParamName:'page',
        el:'',
        isHref:true,
    };

    $.extend(this.params,option)


    this.getPageArr = function(){
        var arr = [];
        var minPage = 1;
        var page = this.params.page;
        var more = false;
        if(this.params.page>this.params.maxPage){
                minPage = 1;
        }else{
            if (this.params.index<= Math.ceil(this.params.page/2)){
                minPage = 1;
            }else if(this.params.index>=this.params.maxPage -  Math.ceil(this.params.page/2)){
                minPage = this.params.maxPage-this.params.page+1;
            }else{
                minPage = this.params.index -  Math.ceil(this.params.page/2);
            }
        }
        if(this.params.maxPage<=0){
            console.log('当前页面分页最大页数有误')
            return {};
        }else if(this.params.maxPage<this.params.page){
            page = this.params.maxPage;
        }else if(this.params.maxPage >this.params.index){
            more = true;
        }
        arr.push({
            text:'首页',
            page:1,
            // url:this.params.url+'?'+this.params.urlParamName+'='+1,
            num:1
        });
        for(var i = 0;i<page;i++){
            var item = {
                text:minPage,
                page:minPage,
                // url:this.params.url+'?'+this.params.urlParamName+'='+(i+1),
                num:i+1
            };
            if(minPage==this.params.index){
                item.onIndex = true;
            }else{
                item.onIndex = false;
            }
            arr.push(item);
            minPage++
        }
        if(more){
            arr.push({
                text:'...',
                notap:true,
                url:false,
            });
        }
        if(this.params.index<this.params.maxPage){
            arr.push({
                text:'下一页',
                page:(this.params.index - 0)+1,
                // url:this.params.url+'?'+this.params.urlParamName+'='+(this.params.index+1),
                num:(this.params.index - 0)+1
            });
            arr.push({
                text:'末页',
                page:this.params.maxPage,
                // url:this.params.url+'?'+this.params.urlParamName+'='+(this.params.maxPage),
                num:this.params.maxPage
            });
        }
        return arr
    }

    this.appendNode = function(){
        $(this.params.el).children().remove();
        var arr  =this.getPageArr();
        for(var i = 0 ;i<arr.length;i++){
            var attr ={};
            if(this.params.isHref&&!arr[i].notap){
                var url = changeURLPar(location.href,this.params.urlParamName,arr[i].page);
                attr.href =url;
            }
            if(arr[i].onIndex){
                attr.class = 'on';
            }
            attr.html = arr[i].text;
            var info = arr[i];
            var item = $('<a>',attr);
            if(this.params.btn_fn&&!arr[i].notap){
                var that = this;
                function a(item,that,info){
                    item.on('click',function(event){
                        that.params.btn_fn(info,event)
                    });
                };
                a(item,that,info);
            }
            $(this.params.el).append(item)
        }
    }

    this.appendNode()

};
